package com.defysoft.waukids;

import android.os.Bundle;
import android.os.Debug;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;

public class Bitmaprecycletest extends BaseActivity {
	DisplayImageOptions options;
	ImageLoader imageLoader;
	ImageView[] iv=new ImageView[8];

@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		recycleBitmap(iv[0].getDrawable());
		recycleBitmap(iv[1].getDrawable());
		recycleBitmap(iv[2].getDrawable());
		recycleBitmap(iv[3].getDrawable());
		recycleBitmap(iv[4].getDrawable());
		recycleBitmap(iv[5].getDrawable());
		recycleBitmap(iv[6].getDrawable());
		recycleBitmap(iv[7].getDrawable());
		RecycleUtils.recursiveRecycle(iv[0]);
		RecycleUtils.recursiveRecycle(iv[1]);
		RecycleUtils.recursiveRecycle(iv[2]);
		RecycleUtils.recursiveRecycle(iv[3]);
		RecycleUtils.recursiveRecycle(iv[4]);
		RecycleUtils.recursiveRecycle(iv[5]);
		RecycleUtils.recursiveRecycle(iv[6]);
		RecycleUtils.recursiveRecycle(iv[7]);

		super.onDestroy();
	}
	
	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.testbitmap);
		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
				this).threadPriority(Thread.NORM_PRIORITY - 2)
				.denyCacheImageMultipleSizesInMemory()
				.discCacheFileNameGenerator(new Md5FileNameGenerator())
				.tasksProcessingOrder(QueueProcessingType.LIFO)
				.writeDebugLogs() // Remove for release app
				.build();
		
		// Initialize ImageLoader with configuration.
		ImageLoader.getInstance().init(config);
		imageLoader = ImageLoader.getInstance();
		imageLoader.clearDiskCache();
		imageLoader.clearMemoryCache();
		options = new DisplayImageOptions.Builder().cacheInMemory(true)
		/* .imageScaleType(ImageScaleType.EXACTLY) */
		.cacheOnDisc(true).considerExifParams(true).build();
		
		iv[0]=(ImageView)findViewById(R.id.testbitmap1);
		iv[1]=(ImageView)findViewById(R.id.testbitmap2);
		iv[2]=(ImageView)findViewById(R.id.testbitmap3);
		iv[3]=(ImageView)findViewById(R.id.testbitmap4);
		iv[4]=(ImageView)findViewById(R.id.testbitmap5);
		iv[5]=(ImageView)findViewById(R.id.testbitmap6);
		iv[6]=(ImageView)findViewById(R.id.testbitmap7);
		iv[7]=(ImageView)findViewById(R.id.testbitmap8);
		
	/*	imageLoader.displayImage("http://waukids.com/photodata/noticephoto/notice_1421997320.75.png", iv[0], options, null);
		imageLoader.displayImage("http://waukids.com/photodata/noticephoto/notice_1421997320.75.png", iv[1], options, null);
		imageLoader.displayImage("http://waukids.com/photodata/noticephoto/notice_1421997320.75.png", iv[2], options, null);
		imageLoader.displayImage("http://waukids.com/photodata/noticephoto/notice_1421997320.75.png", iv[3], options, null);
		imageLoader.displayImage("http://waukids.com/photodata/noticephoto/notice_1421997320.75.png", iv[4], options, null);
		imageLoader.displayImage("http://waukids.com/photodata/noticephoto/notice_1421997320.75.png", iv[5], options, null);
		imageLoader.displayImage("http://waukids.com/photodata/noticephoto/notice_1421997320.75.png", iv[6], options, null);
		imageLoader.displayImage("http://waukids.com/photodata/noticephoto/notice_1421997320.75.png", iv[7], options, null);*/
		double allocateMemory = Debug.getNativeHeapAllocatedSize() / ( 1024.0f );
		((TextView)findViewById(R.id.memoryaaa)).setText(allocateMemory+"");
		
	}
	
	
}
